const api = getApp().globalData.api

Page({
    data: {
        active: 'backlog',
        result: [],
        page: 1,
        pageAll: 0,
    },
    onLoad: async function (obj) {
        const act = obj.act ? obj.act : ''
        await this.getList(act)
    },
    getList: async function (act = 'backlog', page = 1) {
        const url = '?cla=inventoryOther&fun=backlogList&page=' + page
        let res = await api.curlPost(url, {act: act})
        if (res.code === 1) {
            const page = res.data.page
            this.setData({
                active: act,
                result: res.data.result,
                page: page.pageNow,
                pageAll: page.pageAll
            })
        }
    },
    onChange: async function (obj) {
        await this.getList(obj.detail.name)
    },
    // 上拉加载
    onReachBottom() {
        if (!this.loading && this.data.page < this.data.pageAll) {
            const page = parseInt(this.data.page),
                act = this.data.active
            this.getList(act, page + 1)
        }
    },
    // 下拉刷新
    onPullDownRefresh() {
        if (!this.loading) {
            this.getList(this.data.active).then(() => {
                // 处理完成后，终止下拉刷新
                wx.stopPullDownRefresh()
            })
        }
    },
});